<template>
  <el-dialog title="设置对象-个人" :close-on-click-modal="false" :visible.sync="visible" width="800px" top="8vh">
    <div align="right" style="margin-bottom:10px;">
      <el-button type="primary" plain v-if="permissions.ceping_cepinghzglb_add" @click="addUser()">设置人员</el-button>
    </div>
    <el-container>
      <el-main style="max-height:55vh" class="avue-crud">
        <el-table :data="itemData" stripe>
          <el-table-column label="人员名称" prop="userName"></el-table-column>
          <el-table-column label="人员类型" width="120" prop="userLx"></el-table-column>
          <el-table-column label="人员班子" prop="userDeptName" :formatter="formatterSpecial"></el-table-column>
          <el-table-column label="排序号" width="100" prop="bhzPx"></el-table-column>

          <el-table-column label="操作"  width="180">
            <template slot-scope="scope">
              <el-button type="primary" plain v-if="permissions.ceping_cepinghzglb_edit" @click="editBhzpxHandel(scope.row.id)">修改</el-button>
              <el-button type="danger" plain v-if="permissions.ceping_cepinghzglb_del" @click="deleteHandle(scope.row.id)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-main>
    </el-container>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" plain @click="visible = false">取消</el-button>
      <!-- <el-button type="primary" @click="dataFormSubmit()" v-if="canSubmit">确定</el-button> -->
    </span>
    <!--选择人员-->
    <usercomment v-if="usercomment" ref="usercomment" @refreshDataList="getDataList"></usercomment>
    <!--修改排序-->
    <cepinghzgldxpzDialog v-if="bhzpxDialog" ref="editBhzpxDialog" @refreshDataList="getDataList"></cepinghzgldxpzDialog>
  </el-dialog>
</template>

<script>
/*!
 * 绩效考核-测评统计设置对象-个人
 *
 * @author zmk
 * @date 2021-07-08 17:40:00
 */
import { delObj, selHzBmList } from '@/api/ceping/cepinghzgldxpzb'
import usercomment from "./usercomment";
import cepinghzgldxpzDialog from "./cepinghzgldxpzDialog"
import { mapGetters } from 'vuex'

export default {
  data() {
    return {
      hzId: 0,
      visible: false,
      canSubmit: false,
      usercomment: false,
      bhzpxDialog: false,
      itemData: []
    }
  },
  computed: {
    ...mapGetters(['permissions'])
  },
  components: {
    usercomment,
    cepinghzgldxpzDialog
  },
  methods: {
    formatterSpecial(row, column) {
      if (row.userLx === "班子") {
        return row.userDeptName;
      }
    },
    //增加人员
    addUser() {
      this.usercomment = true;
      this.$nextTick(() => {
        this.$refs.usercomment.init(this.hzId);
      });
    },
    //初始化
    csh() {

    },
    init(id) {
      this.hzId = id;
      this.csh();
      this.visible = true;
      this.canSubmit = true;

      this.$nextTick(() => {
        if (this.hzId) {
          this.getDataList();
        }
      });
    },
    getDataList() {
      selHzBmList(this.hzId).then(response => {
        this.itemData = response.data.data
      })
    },
    // 删除
    deleteHandle(id) {
      this.$confirm('是否确认删除', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function () {
        return delObj(id)
      }).then(data => {
        this.$notify.closeAll();
        this.$notify.success('删除成功')
        this.getDataList()
      }).catch(() => { });
    },
    //修改
    editBhzpxHandel(id) {
      this.bhzpxDialog = true;
      this.$nextTick(() => {
        this.$refs.editBhzpxDialog.init(id);
      });
    }
  }
}
</script>
